package com.kelly.kellymusicplayer.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.kelly.kellymusicplayer.R;
import com.kelly.kellymusicplayer.entity.MusicInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by kelly on 2015/12/23.
 */
public class MusicListAdapter extends BaseAdapter{

    private Context mContext;
    private List<MusicInfo> musicInfoList = new ArrayList<>();

    public MusicListAdapter(Context mContext, List<MusicInfo> musicInfoList) {
        this.mContext = mContext;
        this.musicInfoList = musicInfoList;
    }

    @Override
    public int getCount() {
        return musicInfoList.size();
    }

    @Override
    public Object getItem(int i) {
        return musicInfoList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return musicInfoList.get(i).getId();
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if(view == null){
            viewHolder = new ViewHolder();
            view = View.inflate(mContext, R.layout.item_music_list,null);
            TextView tv_music_name = (TextView) view.findViewById(R.id.tv_music_name);
            viewHolder.tv_music_name = tv_music_name;
            view.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.tv_music_name.setText(musicInfoList.get(i).getAlbum());
        return view;
    }


    private class ViewHolder{
        public TextView tv_music_name;
    }
}
